package com.bbva.gptf.back.dominio;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;

import com.bbva.gptf.dto.bean.Bench;

@RooJavaBean
@RooToString
@RooEntity(identifierType = Tgpt008PortaBenchPK.class, versionField = "", table = "TGPT008_PORTA_BENCH", schema = "DBSGPT")
@RooDbManaged(automaticallyDelete = true)
public class Tgpt008PortaBench {

	@SuppressWarnings("unchecked")
	public static List<Bench> obtenerBench() {
		try {
			final String qlString = "SELECT DISTINCT new com.bbva.gptf.dto.bean.Bench"
					+ " (bench.id.nbPortafolio) FROM Tgpt008PortaBench bench order by bench.id.nbPortafolio ";
			return entityManager().createQuery(qlString).getResultList();
		} catch (final Exception e) {
			e.printStackTrace();
		}
		return new ArrayList<Bench>();
	}

	@SuppressWarnings("unchecked")
	public static Bench obtenerBenchmarckPorNombre(final String nbPortafolio) {
		try {
			if (StringUtils.isBlank(nbPortafolio)) {
				return new Bench();
			}
			final String qlString = "SELECT DISTINCT new com.bbva.gptf.dto.bean.Bench"
					+ " (bench.id.nbPortafolio) FROM Tgpt008PortaBench bench "
					+ " WHERE bench.id.nbPortafolio = :nbPortafolio order by bench.id.nbPortafolio ";
			return (Bench) entityManager().createQuery(qlString)
					.setParameter("nbPortafolio", nbPortafolio)
					.getSingleResult();
		} catch (final Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return new Bench();
	}

	@SuppressWarnings("unchecked")
	public static List<Bench> obtenerBenchMarckPorNombreLike(String nbPortafolio) {
		try {
			if (StringUtils.isBlank(nbPortafolio)) {
				return new ArrayList<Bench>();
			}
			nbPortafolio = nbPortafolio.toUpperCase();
			final String qlString = "SELECT DISTINCT new com.bbva.gptf.dto.bean.Bench"
					+ " (bench.id.nbPortafolio) FROM Tgpt008PortaBench bench "
					+ " WHERE UPPER(bench.id.nbPortafolio) LIKE :nbPortafolio order by bench.id.nbPortafolio ";
			return entityManager().createQuery(qlString)
					.setParameter("nbPortafolio", nbPortafolio).getResultList();
		} catch (final Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return new ArrayList<Bench>();
	}
}
